package com.etlmaster.executor.steps.table;

import java.io.IOException;

import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import com.etlmaster.executor.Step;
import com.etlmaster.executor.StepMeta;
import com.etlmaster.executor.annotation.StepInstruction;
import com.etlmaster.executor.bigdata.hbase.HbaseUtil;
import com.etlmaster.executor.utils.StepState;

/**
 * @author Larry
 * @copyright Larry@etlMaster
 * @since 2017-09-10
 */
@StepInstruction("dropHbaseTab")
public class DropHbaseTableStep extends Step{

	private DropHbaseTableStepMeta meta;
	public DropHbaseTableStep(StepMeta meta) {
		super(meta);
		this.meta=(DropHbaseTableStepMeta) meta;
	}

	@Override
	protected int handle() {
		HBaseAdmin admin=null;
		try {
			admin=new HBaseAdmin(HbaseUtil.getConf());
			HbaseUtil.delete(admin, meta.getTableName());
			meta.log("INFO","表[{}]删除成功",meta.getTableName());
			return StepState.RUNNING_SUCCESSED;
		} catch (MasterNotRunningException e) {
			meta.log("ERROR",e.getMessage());
		} catch (ZooKeeperConnectionException e) {
			meta.log("ERROR",e.getMessage());
		} catch (IOException e) {
			meta.log("ERROR",e.getMessage());
		}catch(Exception e){
			meta.log("ERROR",e.getMessage());
		}finally{
			HbaseUtil.closeAdmin(admin);
		}
		meta.log("ERROR","表[{}]删除失败",meta.getTableName());
		return StepState.RUNNING_FAILED;
	}

	@Override
	public boolean stop() {
		// TODO Auto-generated method stub
		return false;
	}

}
